from flask import Blueprint, current_app, jsonify
from app.utils.code import RET
from app.models import DeviceModel

api_device = Blueprint("api_device", __name__)


''' 获取房屋设备 '''
@api_device.route('/devices', methods=["GET"])
def get_devices():
    try:
        devices = DeviceModel.query.order_by(DeviceModel.id.asc()).all()
        return jsonify(errno = RET.OK, errmsg = "获取成功", data = [device.to_json() for device in devices])
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg="数据库异常")